package SpellCheck;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TextReader {

	public Map<String,String> ReadFile(String fName)
	{
		String LineSperator = System.getProperty("line.separator");
		String line;
		Map<String,String> repo = new HashMap<String,String>();
		FileReader fr = null;
		BufferedReader bfr = null;
		try {
			 fr = new FileReader(fName);
			 bfr = new BufferedReader(fr);
			int counter =0;
			while(null != (line = bfr.readLine()))
			{
				Integer tt = new Integer(counter++);
				System.out.println("int value is"+tt);
				System.out.println("value of line"+line);
				repo.put(tt.toString(), line);
			}
			
			fr.close();
			bfr.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			
			try {
				fr.close();
				bfr.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return repo;
	}
	
	public List<String> ReadWordsFromFile(String fName)
	{
		String LineSperator = System.getProperty("line.separator");
		String line;
		List<String> repo = new ArrayList<String>();
		FileReader fr = null;
		BufferedReader bfr = null;
		try {
			 fr = new FileReader(fName);
			 bfr = new BufferedReader(fr);
			int counter =0;
			while(null != (line = bfr.readLine()))
			{
				Integer tt = new Integer(counter++);
				//System.out.println("S.NO"+tt+" value:: "+line);
				
				repo.add( line);
			}
			
			fr.close();
			bfr.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			
			try {
				fr.close();
				bfr.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return repo;
	}
}
